package com.fjnldx.mes.mapper.scddglMapper;

import com.fjnldx.mes.domain.domainReq.DevWork;
import com.fjnldx.mes.domain.domainReq.DingerReq;
import com.fjnldx.mes.domain.domainReq.ModifyPrePlanReq;
import com.fjnldx.mes.domain.domainReq.PrePlanQuery;
import com.fjnldx.mes.domain.domainRes.OrderInfo;
import com.fjnldx.mes.domain.domainRes.PrePlanRes;
import com.fjnldx.mes.domain.pojo.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface SecMapper {

    /*
     * 新增订单
     */
    @Insert("insert into fzy_ddgl(ddbh,org,ddlx,pz,zb,zl,ddjq,merge,status,update_time) " +
            "values(#{ddbh},#{org},#{ddlx},#{pz},#{zb},#{zl},#{ddjq},#{merge},#{status},#{update_time})")
    int insertOrder(Order data);

    /**
     * 订单查询
     *
     * @return
     */
    @Select("<script>" +
            " SELECT * FROM fzy_ddgl " +
            " WHERE 1=1" +
            "<if test=\"id!=null\"> AND id=#{id} </if>" +
            "<if test=\"ddbh!=null and ddbh!=''\"> AND ddbh=#{ddbh} </if>" +
            "<if test=\"org!=null and org!=''\"> AND org=#{org} </if>" +
            "<if test=\"ddlx!=null and ddlx!=''\"> AND ddlx=#{ddlx} </if>" +
            "<if test=\"pz!=null and pz!=''\"> AND pz=#{pz} </if>" +
            "<if test=\"zb!=null and zb!=''\"> AND zb=#{zb} </if>" +
            "<if test=\"zl!=null and zl!=''\"> AND zl=#{zl} </if>" +
            "<if test=\"merge!=null and merge!=''\"> AND merge=#{merge} </if>" +
            "<if test=\"status!=null and status!=''\"> AND status=#{status} </if>" +
            "<if test=\"ddjq!=null \"> AND DATEDIFF(ddjq,date(#{ddjq}))=0  </if>" +
            "<if test=\"update_time!=null \"> AND DATEDIFF(update_time,date(#{update_time}))=0  </if>" +
            "ORDER BY update_time DESC " +
            "<if test='size!=-1'> limit ${page*size},#{size} </if>" +
            "</script>")
    List<Order> queryOrder(Order data);

    /**
     * 获取当前订单total
     *
     * @return
     */
    @Select("<script>" +
            "SELECT count(*) FROM ( " +
            " SELECT * FROM fzy_ddgl " +
            " WHERE 1=1" +
            "<if test=\"id!=null\"> AND id=#{id} </if>" +
            "<if test=\"ddbh!=null and ddbh!=''\"> AND ddbh=#{ddbh} </if>" +
            "<if test=\"org!=null and org!=''\"> AND org=#{org} </if>" +
            "<if test=\"ddlx!=null and ddlx!=''\"> AND ddlx=#{ddlx} </if>" +
            "<if test=\"pz!=null and pz!=''\"> AND pz=#{pz} </if>" +
            "<if test=\"zb!=null and zb!=''\"> AND zb=#{zb} </if>" +
            "<if test=\"zl!=null and zl!=''\"> AND zl=#{zl} </if>" +
            "<if test=\"merge!=null and merge!=''\"> AND merge=#{merge} </if>" +
            "<if test=\"status!=null and status!=''\"> AND status=#{status} </if>" +
            "<if test=\"ddjq!=null \"> AND DATEDIFF(ddjq,date(#{ddjq}))=0  </if>" +
            "<if test=\"update_time!=null \"> AND DATEDIFF(update_time,date(#{update_time}))=0  </if>" +
            ") a " +
            "</script>")
    int queryTotalOrder(Order data);

    /**
     * 删除订单
     */
    @Delete("<script>" +
            "DELETE FROM fzy_ddgl WHERE ddbh In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int deleteOrder(String[] array);

    /**
     * 更新订单
     */
    @Update("<script>" +
            "update fzy_ddgl " +
            "<trim prefix='set' suffixOverrides=','> " +
            "<if test='ddbh!=null'> ddbh=#{ddbh}, </if>" +
            "<if test='org!=null'> org=#{org}, </if>" +
            "<if test='ddlx !=null'> ddlx=#{ddlx}, </if>" +
            "<if test='pz !=null'> pz=#{pz}, </if>" +
            "<if test='zb!=null'>  zb=#{zb}, </if>" +
            "<if test='zl!=null'> zl=#{zl}, </if>" +
            "<if test='ddjq!=null'> ddjq=#{ddjq}, </if>" +
            "<if test='merge!=null'> merge=#{merge}, </if>" +
            "<if test='status!=null'> status=#{status}, </if>" +
            "<if test='update_time!=null'> update_time=#{update_time}, </if>" +
            "</trim> " +
            " WHERE id=#{id}" +
            "</script>")
    int updateOrder(Order data);

    /*
     * 设备字典
     */
    @Insert("insert into fzy_dev_dictionary(gongxu,devSn) " +
            "values(#{gongxu},#{devSn})")
    void insertDevSn(String gongxu, String devSn);

    /**
     * 设备字典查询
     */
    @Select(" SELECT * FROM fzy_dev_dictionary ")
    List<DevDictionary> queryDevDictionary();

    /*
     * 新增生产计划
     */
    @Insert("insert into mes_newscjh(scjhbh,devSn,pz,gongxu,dcg,gh,time) " +
            "values(#{ddbh},#{devSn},#{pz},#{gongxu},#{dcg},#{gh},#{time})")
    void insertScjh(DevWork devWork);

    /**
     * 二级订单查询
     */
    @Select("<script>" +
            "SELECT * FROM fzy_ddgl_sec " +
            "WHERE oriddbh=#{oriddbh} " +
            "<if test=\"id!=null \"> AND id=#{id} </if>" +
            "<if test=\"ddbh!=null and ddbh!=''\"> AND ddbh=#{ddbh} </if>" +
            "<if test=\"org!=null and org!=''\"> AND org=#{org} </if>" +
            "<if test=\"ddlx!=null and ddlx!=''\"> AND ddlx=#{ddlx} </if>" +
            "<if test=\"pz!=null and pz!=''\"> AND pz=#{pz} </if>" +
            "<if test=\"zb!=null and zb!=''\"> AND zb=#{zb} </if>" +
            "<if test=\"zl!=null and zl!=''\"> AND zl=#{zl} </if>" +
            "<if test=\"ddjq!=null \"> AND DATEDIFF(ddjq,date(#{ddjq}))=0 </if>" +
            "<if test=\"update_time!=null \"> AND DATEDIFF(update_time,date(#{update_time}))=0 </if>" +
            "<if test=\"status!=null and status!=''\"> AND status=#{status} </if>" +
            "ORDER BY update_time DESC " +
            "<if test='size!=-1'> limit ${page*size},#{size} </if>" +
            "</script>")
    List<OrderSec> queryOrderSec(OrderSec data);

    /**
     * 获取二级订单total
     *
     * @return
     */
    @Select("<script>" +
            " SELECT count(*) FROM (  " +
            "SELECT * FROM fzy_ddgl_sec " +
            "WHERE oriddbh=#{oriddbh} " +
            "<if test=\"id!=null \"> AND id=#{id} </if>" +
            "<if test=\"ddbh!=null and ddbh!=''\"> AND ddbh=#{ddbh} </if>" +
            "<if test=\"org!=null and org!=''\"> AND org=#{org} </if>" +
            "<if test=\"ddlx!=null and ddlx!=''\"> AND ddlx=#{ddlx} </if>" +
            "<if test=\"pz!=null and pz!=''\"> AND pz=#{pz} </if>" +
            "<if test=\"zb!=null and zb!=''\"> AND zb=#{zb} </if>" +
            "<if test=\"zl!=null and zl!=''\"> AND zl=#{zl} </if>" +
            "<if test=\"ddjq!=null \"> AND DATEDIFF(ddjq,date(#{ddjq}))=0 </if>" +
            "<if test=\"update_time!=null \"> AND DATEDIFF(update_time,date(#{update_time}))=0 </if>" +
            "<if test=\"status!=null and status!=''\"> AND status=#{status} </if>" +
            ") a " +
            "</script>")
    int queryTotalOrderSec(OrderSec data);

    /**
     * 计算二级订单-重量
     */
    @Select("SELECT sum(zl) FROM fzy_ddgl_sec WHERE oriddbh=#{oriddbh} ")
    String queryDdglSecZlCount(String oriddbh);

    /*
     * 新增二级订单
     */
    @Insert("insert into fzy_ddgl_sec(ddbh,oriddbh,org,ddlx,pz,zb,zl,ddjq,update_time,status) " +
            "values(#{ddbh},#{oriddbh},#{org},#{ddlx},#{pz},#{zb},#{zl},#{ddjq},#{update_time},#{status})")
    int insertOrderSec(OrderSec data);

    /**
     * 删除二级订单
     */
    @Delete("<script>" +
            "DELETE FROM fzy_ddgl_sec WHERE oriddbh=#{oriddbh} AND ddbh In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int deleteOrderSec(String[] array, String oriddbh);

    @Delete("<script>" +
            "DELETE FROM fzy_ddgl_sec WHERE oriddbh In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int deleteOrderSecOri(String[] array);

    /**
     * 更新二级订单
     */
    @Update("<script>" +
            "update fzy_ddgl_sec " +
            "<trim prefix='set' suffixOverrides=','> " +
            "<if test='ddbh!=null'> ddbh=#{ddbh}, </if>" +
            "<if test='org!=null'> org=#{org}, </if>" +
            "<if test='ddlx !=null'> ddlx=#{ddlx}, </if>" +
            "<if test='pz!=null'> pz=#{pz}, </if>" +
            "<if test='zb!=null'> zb=#{zb}, </if>" +
            "<if test='zl!=null'> zl=#{zl}, </if>" +
            "<if test='ddjq!=null'> ddjq=#{ddjq}, </if>" +
            "<if test='update_time!=null'> update_time=#{update_time}, </if>" +
            "<if test='status!=null'> status=#{status}, </if>" +
            "</trim> " +
            " WHERE id=#{id}" +
            "</script>")
    int updateOrderSec(OrderSec data);

    /**
     * 更新订单操作时间
     */
    @Update("<script>" +
            "UPDATE fzy_ddgl SET update_time = now() WHERE ddbh = #{ddbh}" +
            "</script>")
    int updateOrderUpdateTime(String ddbh);

    /**
     * 更新订单操作时间二级
     */
    @Update("<script>" +
            "UPDATE fzy_ddgl_sec SET update_time = now() WHERE ddbh = #{ddbh} AND oriddbh=#{oriddbh}" +
            "</script>")
    int updateOrderUpdateTimeSec(String oriddbh, String ddbh);

    /*
     * 新增预排计划
     */
    @Insert("insert into fzy_pre_plan(ddbh,pre_bh,time,cj,status,update_time,jhkt,jhtt,jhcl,jhtc,llcl,start_time,end_time) " +
            "values(#{ddbh},#{pre_bh},#{time},#{cj},#{status},#{update_time},#{jhkt},#{jhtt},#{jhcl},#{jhtc},#{llcl},#{start_time},#{end_time})")
    void insertPrePlan(PrePlan data);

    /**
     * 预排计划查询
     */
    @Select("<script>" +
            "SELECT a.*,b.org,b.ddlx,b.pz,b.zb,b.zl,b.ddjq FROM ( " +
            "SELECT * FROM fzy_pre_plan " +
            "WHERE 1=1" +
            "<if test='id!=null'> AND id=#{id} </if>" +
            "<if test=\"ddbh!=null and ddbh!=''\">AND ddbh=#{ddbh} </if>" +
            "<if test=\"pre_bh!=null and pre_bh!=''\"> AND pre_bh=#{pre_bh} </if>" +
            "<if test=\"time!=null \"> AND DATEDIFF(time,#{time})=0 </if>" +
            "<if test=\"cj!=null and cj!=''\"> AND cj=#{cj} </if>" +
            "<if test=\"status!=null and status!=''\"> AND status=#{status} </if>" +
            "<if test=\"update_time!=null \"> AND DATEDIFF(update_time,#{update_time})=0 </if>" +
            "<if test=\"jhkt!=null and jhkt!=''\"> AND jhkt=#{jhkt} </if>" +
            "<if test=\"jhtt!=null and jhtt!=''\"> AND jhtt=#{jhtt} </if>" +
            "<if test=\"jhcl!=null and jhcl!=''\"> AND jhcl=#{jhcl} </if>" +
            "<if test=\"jhtc!=null and jhtc!=''\"> AND jhtc=#{jhtc} </if>" +
            "<if test=\"llcl!=null and llcl!=''\"> AND llcl=#{llcl} </if>" +
            "<if test=\"start_time!=null\"> AND DATEDIFF(start_time,#{start_time})=0 </if>" +
            "<if test=\"end_time!=null\"> AND DATEDIFF(end_time,#{end_time})=0 </if>" +
            "<if test=\"query_time!=null \"> AND date_format(time,'%Y-%m')=#{query_time} </if>" +
            "<if test='size!=-1'> limit ${page*size},#{size} </if>" +
            ") a LEFT JOIN\n" +
            "(SELECT ddbh,org,ddlx,pz,zb,zl,ddjq FROM fzy_ddgl) b\n" +
            "ON a.ddbh=b.ddbh " +
            "</script>")
    List<PrePlanRes> queryPrePlan(PrePlan data);

    /**
     * 获取当前查询total
     */
    @Select("<script>" +
            "SELECT count(*) FROM ( " +
            "SELECT * FROM fzy_pre_plan " +
            "WHERE 1=1" +
            "<if test='id!=null'> AND id=#{id} </if>" +
            "<if test=\"ddbh!=null and ddbh!=''\">AND ddbh=#{ddbh} </if>" +
            "<if test=\"pre_bh!=null and pre_bh!=''\"> AND pre_bh=#{pre_bh} </if>" +
            "<if test=\"time!=null \"> AND DATEDIFF(time,#{time})=0 </if>" +
            "<if test=\"cj!=null and cj!=''\"> AND cj=#{cj} </if>" +
            "<if test=\"status!=null and status!=''\"> AND status=#{status} </if>" +
            "<if test=\"update_time!=null \"> AND DATEDIFF(update_time,#{update_time})=0 </if>" +
            "<if test=\"jhkt!=null and jhkt!=''\"> AND jhkt=#{jhkt} </if>" +
            "<if test=\"jhtt!=null and jhtt!=''\"> AND jhtt=#{jhtt} </if>" +
            "<if test=\"jhcl!=null and jhcl!=''\"> AND jhcl=#{jhcl} </if>" +
            "<if test=\"jhtc!=null and jhtc!=''\"> AND jhtc=#{jhtc} </if>" +
            "<if test=\"llcl!=null and llcl!=''\"> AND llcl=#{llcl} </if>" +
            "<if test=\"start_time!=null\"> AND DATEDIFF(start_time,#{start_time})=0 </if>" +
            "<if test=\"end_time!=null\"> AND DATEDIFF(end_time,#{end_time})=0 </if>" +
            "<if test=\"query_time!=null \"> AND date_format(time,'%Y-%m')=#{query_time} </if>" +
            ") a " +
            "</script>")
    int queryPrePlanTotal(PrePlanQuery data);

    /**
     * 删除预排计划记录
     */
    @Delete("<script>" +
            "DELETE FROM fzy_pre_plan WHERE id In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    void deletePrePlan(String[] array);

    /**
     * 根据订单编号删除预排计划记录
     */
    @Delete("<script>" +
            "DELETE FROM fzy_pre_plan WHERE ddbh=#{data}" +
            "</script>")
    void deletePrePlanByOrder(String data);

    /**
     * 修改预排计划记录
     */
    @Update("<script>" +
            "UPDATE fzy_pre_plan " +
            "<trim prefix='set' suffixOverrides=','> " +
            "<if test=\" cj!=null and cj!='' \"> cj=#{cj}, </if>" +
            "<if test=\" jhkt!=null and jhkt!='' \"> jhkt=#{jhkt}, </if>" +
            "<if test=\" jhtt!=null and jhtt!='' \"> jhtt=#{jhtt}, </if>" +
            "<if test=\" jhcl!=null and jhcl!='' \"> jhcl=#{jhcl}, </if>" +
            "<if test=\" jhtc!=null and jhtc!='' \"> jhtc=#{jhtc}, </if>" +
            "<if test=\" llcl!=null and llcl!='' \"> llcl=#{llcl}, </if>" +
            "</trim> " +
            " WHERE id=#{id}" +
            "</script>")
    void modifyPrePlan(ModifyPrePlanReq data);

    /**
     * 新增预排计划-根据订单编号查询订单信息
     */
    @Select("SELECT ddbh,zl,pz,ddlx,zb,ddjq FROM fzy_ddgl WHERE ddbh = #{ddbh}")
    List<OrderInfo> queryOrderInfoByOrderNumber(String ddbh);

    // ========================


    /**
     * 根据品种进行定额查询
     */
    @Select("<script>" +
            "SELECT * FROM mes_dinger WHERE pz=#{pz} AND gongxu=#{gongxu} " +
            "</script>")
    List<MesDinger> queryDingErByPzAndGongxu(DingerReq dingerReq);


    //    ================
    /*
     * 生产计划
     */
    @Insert("insert into mes_newscjh_info(ddbh,org,cj,gongxu,qfpz,csgs,chph,pz,devSn,qfcjtz,ltcjtz,ybkt,qk,jhts,jakt,ds,dl,cs,xiaolv,der,jhcl,time,scjhbh) " +
            "values(#{ddbh},#{org},#{cj},#{gongxu},#{qfpz},#{csgs},#{chph},#{pz},#{devSn},#{qfcjtz},#{ltcjtz},#{ybkt},#{qk},#{jhts},#{jakt},#{ds},#{dl},#{cs},#{xiaolv},#{der},#{jhcl},#{time},#{scjhbh})")
    int insertScjh2(MesNewscjhInfo mesNewscjhInfo);

    /**
     * 生产计划查询
     */
    @Select("<script>" +
            " SELECT * FROM mes_newscjh_info " +
            " WHERE 1=1" +
            "<if test='id!=null'> AND id=#{id} </if>" +
            "<if test=\"ddbh!=null and ddbh!=''\"> AND ddbh=#{ddbh} </if>" +
            "<if test=\"org!=null and org!=''\"> AND org=#{org} </if>" +
            "<if test=\"cj !=null and cj!=''\"> AND cj=#{cj} </if>" +
            "<if test=\"gongxu!=null and gongxu !=''\"> AND gongxu=#{gongxu} </if>" +
            "<if test='qfpz!=null'> AND qfpz=#{qfpz} </if>" +
            "<if test='csgs!=null'> AND csgs=#{csgs} </if>" +
            "<if test='chph!=null'> AND chph=#{chph} </if>" +
            "<if test=\"pz!=null and pz!=''\"> AND pz=#{pz} </if>" +
            "<if test='devSn!=null'> AND devSn=#{devSn} </if>" +
            "<if test='qfcjtz!=null'> AND qfcjtz=#{qfcjtz} </if>" +
            "<if test='ltcjtz!=null'> AND ltcjtz=#{ltcjtz} </if>" +
            "<if test='ybkt!=null'> AND ybkt=#{ybkt} </if>" +
            "<if test='qk!=null'> AND qk=#{qk} </if>" +
            "<if test='jhts!=null'> AND jhts=#{jhts} </if>" +
            "<if test='jakt!=null'> AND jakt=#{jakt} </if>" +
            "<if test='ds!=null'> AND ds=#{ds} </if>" +
            "<if test='dl!=null'> AND dl=#{dl} </if>" +
            "<if test='cs!=null'> AND cs=#{cs} </if>" +
            "<if test='xiaolv!=null'> AND xiaolv=#{xiaolv} </if>" +
            "<if test='der!=null'> AND der=#{der} </if>" +
            "<if test='jhcl!=null'> AND jhcl=#{jhcl} </if>" +
            "<if test='rjhdh!=null'> AND rjhdh=#{rjhdh} </if>" +
            "<if test=\"ypjh!=null and ypjh !='' \"> AND ypjh=#{ypjh} </if>" +
            "<if test='cjr!=null'> AND cjr=#{cjr} </if>" +
            "<if test='yqrq!=null'> AND yqrq=#{yqrq} </if>" +
            "<if test='status!=null'> AND status=#{status} </if>" +
            "<if test='size!=-1'> limit ${page*size},#{size} </if>" +
            "<if test='time!=null'> AND  DATEDIFF(time,date(#{time}))=0 </if>" +
            "</script>")
    List<MesNewscjhInfo> queryScjh(MesNewscjhInfo mesNewscjhInfo);

    /**
     * 获取生产计划total
     *
     * @return
     */
    @Select("<script>" +
            "SELECT count(*) FROM ( " +
            " SELECT * FROM mes_newscjh_info " +
            " WHERE 1=1" +
            "<if test='id!=null'> AND id=#{id} </if>" +
            "<if test=\"ddbh!=null and ddbh!=''\"> AND ddbh=#{ddbh} </if>" +
            "<if test=\"org!=null and org!=''\"> AND org=#{org} </if>" +
            "<if test=\"cj !=null and cj!=''\"> AND cj=#{cj} </if>" +
            "<if test=\"gongxu!=null and gongxu !=''\"> AND gongxu=#{gongxu} </if>" +
            "<if test='qfpz!=null'> AND qfpz=#{qfpz} </if>" +
            "<if test='csgs!=null'> AND csgs=#{csgs} </if>" +
            "<if test='chph!=null'> AND chph=#{chph} </if>" +
            "<if test=\"pz!=null and pz!=''\"> AND pz=#{pz} </if>" +
            "<if test='devSn!=null'> AND devSn=#{devSn} </if>" +
            "<if test='qfcjtz!=null'> AND qfcjtz=#{qfcjtz} </if>" +
            "<if test='ltcjtz!=null'> AND ltcjtz=#{ltcjtz} </if>" +
            "<if test='ybkt!=null'> AND ybkt=#{ybkt} </if>" +
            "<if test='qk!=null'> AND qk=#{qk} </if>" +
            "<if test='jhts!=null'> AND jhts=#{jhts} </if>" +
            "<if test='jakt!=null'> AND jakt=#{jakt} </if>" +
            "<if test='ds!=null'> AND ds=#{ds} </if>" +
            "<if test='dl!=null'> AND dl=#{dl} </if>" +
            "<if test='cs!=null'> AND cs=#{cs} </if>" +
            "<if test='xiaolv!=null'> AND xiaolv=#{xiaolv} </if>" +
            "<if test='der!=null'> AND der=#{der} </if>" +
            "<if test='jhcl!=null'> AND jhcl=#{jhcl} </if>" +
            "<if test='rjhdh!=null'> AND rjhdh=#{rjhdh} </if>" +
            "<if test=\"ypjh!=null and ypjh !='' \"> AND ypjh=#{ypjh} </if>" +
            "<if test='cjr!=null'> AND cjr=#{cjr} </if>" +
            "<if test='yqrq!=null'> AND yqrq=#{yqrq} </if>" +
            "<if test='status!=null'> AND status=#{status} </if>" +
            "<if test='time!=null'> AND  DATEDIFF(time,date(#{time}))=0 </if>" +
            ") a " +
            "</script>")
    int queryTotalScjh(MesNewscjhInfo mesNewscjhInfo);

    /**
     * 删除生产计划
     */
    @Delete("<script>" +
            "DELETE FROM mes_newscjh_info WHERE id In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int deleteScjh(String[] array);

    /**
     * 更新生产计划
     */
    @Update("<script>" +
            "update mes_newscjh_info " +
            "<trim prefix='set' suffixOverrides=','> " +
            "<if test='ddbh!=null'> ddbh=#{ddbh}, </if>" +
            "<if test='org!=null'> org=#{org}, </if>" +
            "<if test='cj !=null'> cj=#{cj}, </if>" +
            "<if test='gongxu !=null'> gongxu=#{gongxu}, </if>" +
            "<if test='qfpz!=null'>  qfpz=#{qfpz}, </if>" +
            "<if test='csgs!=null'> csgs=#{csgs}, </if>" +
            "<if test='chph!=null'> chph=#{chph}, </if>" +
            "<if test='pz!=null'> pz=#{pz}, </if>" +
            "<if test='devSn!=null'> devSn=#{devSn}, </if>" +
            "<if test='qfcjtz!=null'> qfcjtz=#{qfcjtz}, </if>" +
            "<if test='ltcjtz!=null'> ltcjtz=#{ltcjtz}, </if>" +
            "<if test='ybkt!=null'> ybkt=#{ybkt}, </if>" +
            "<if test='qk!=null'> qk=#{qk}, </if>" +
            "<if test='jhts!=null'> jhts=#{jhts}, </if>" +
            "<if test='jakt!=null'> jakt=#{jakt}, </if>" +
            "<if test='ds!=null'> ds=#{ds}, </if>" +
            "<if test='dl!=null'> dl=#{dl}, </if>" +
            "<if test='cs!=null'> cs=#{cs}, </if>" +
            "<if test='xiaolv!=null'> xiaolv=#{xiaolv}, </if>" +
            "<if test='der!=null'> der=#{der}, </if>" +
            "<if test='jhcl!=null'> jhcl=#{jhcl}, </if>" +
            "<if test='rjhdh!=null'> rjhdh=#{rjhdh}, </if>" +
            "<if test='ypjh!=null'> ypjh=#{ypjh}, </if>" +
            "<if test='cjr!=null'> cjr=#{cjr}, </if>" +
            "<if test='yqrq!=null'> yqrq=#{yqrq}, </if>" +
            "<if test='status!=null'> status=#{status}, </if>" +
            "</trim> " +
            " WHERE id=#{id}" +
            "</script>")
    int updateScjh(MesNewscjhInfo mesNewscjhInfo);

    /*
     * 生产计划二级
     */
    @Insert("insert into mes_newscjh(scjhbh,devSn,gongxu,dcg,gh,time,bc,org,cj,kbsj,ktsj,ttsj,yl,xiaolv,pz) " +
            "values(#{scjhbh},#{devSn},#{gongxu},#{dcg},#{gh},#{time},#{bc},#{org},#{cj},#{kbsj},#{ktsj},#{ttsj},#{yl},#{xiaolv},#{pz})")
    int insertScjhSec(MesNewscjhInfo mesNewscjhInfo);

    /**
     * 生产计划查询二级
     */
    @Select("<script>" +
            " SELECT * FROM mes_newscjh " +
            " WHERE scjhbh=#{scjhbh} " +
            "<if test='id!=null'> AND id=#{id} </if>" +
            "<if test='devSn!=null'> AND devSn=#{devSn} </if>" +
            "<if test='pz!=null'> AND pz=#{pz} </if>" +
            "<if test='gongxu!=null'> AND gongxu=#{gongxu} </if>" +
            "<if test='dcg!=null'> AND dcg=#{dcg} </if>" +
            "<if test='gh!=null'> AND gh=#{gh} </if>" +
            "<if test='bc!=null'> AND bc=#{bc} </if>" +
            "<if test='org!=null'> AND org=#{org} </if>" +
            "<if test='cj!=null'> AND cj=#{cj} </if>" +
            "<if test='kbsj!=null'> AND kbsj=#{kbsj} </if>" +
            "<if test='ktsj!=null'> AND ktsj=#{ktsj} </if>" +
            "<if test='ttsj!=null'> AND ttsj=#{ttsj} </if>" +
            "<if test='yl!=null'> AND yl=#{yl} </if>" +
            "<if test='xiaolv!=null'> AND xiaolv=#{xiaolv} </if>" +
            "<if test='time!=null'> AND  DATEDIFF(#{time},date(time))=0 </if>" +
            "<if test='size!=-1'> limit ${page*size},#{size} </if>" +
            "</script>")
    List<MesNewscjh> queryScjhSec(MesNewscjhInfo mesNewscjhInfo);

    /**
     * 获取生产计划total二级
     */
    @Select("<script>" +
            "SELECT count(*) FROM ( " +
            " SELECT * FROM mes_newscjh " +
            " WHERE scjhbh=#{scjhbh} " +
            "<if test='id!=null'> AND id=#{id} </if>" +
            "<if test='devSn!=null'> AND devSn=#{devSn} </if>" +
            "<if test='pz!=null'> AND pz=#{pz} </if>" +
            "<if test='gongxu!=null'> AND gongxu=#{gongxu} </if>" +
            "<if test='dcg!=null'> AND dcg=#{dcg} </if>" +
            "<if test='gh!=null'> AND gh=#{gh} </if>" +
            "<if test='bc!=null'> AND bc=#{bc} </if>" +
            "<if test='org!=null'> AND org=#{org} </if>" +
            "<if test='cj!=null'> AND cj=#{cj} </if>" +
            "<if test='kbsj!=null'> AND kbsj=#{kbsj} </if>" +
            "<if test='ktsj!=null'> AND ktsj=#{ktsj} </if>" +
            "<if test='ttsj!=null'> AND ttsj=#{ttsj} </if>" +
            "<if test='yl!=null'> AND yl=#{yl} </if>" +
            "<if test='xiaolv!=null'> AND xiaolv=#{xiaolv} </if>" +
            "<if test='time!=null'> AND  DATEDIFF(#{time},date(time))=0 </if>" +
            ") a " +
            "</script>")
    int queryTotalScjhSec(MesNewscjhInfo mesNewscjhInfo);

    /**
     * 删除生产计划二级
     */
    @Delete("<script>" +
            "DELETE FROM mes_newscjh WHERE id In" +
            "<foreach collection='array' item='item' index='index' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    int deleteScjhSec(String[] array);

    /**
     * 更新生产计划二级
     */
    @Update("<script>" +
            "update mes_newscjh " +
            "<trim prefix='set' suffixOverrides=','> " +
            "<if test='scjhbh!=null'> scjhbh=#{scjhbh}, </if>" +
            "<if test='devSn!=null'> org=#{org}, </if>" +
            "<if test='pz !=null'> cj=#{cj}, </if>" +
            "<if test='gongxu !=null'> gongxu=#{gongxu}, </if>" +
            "<if test='dcg!=null'>  ddbh=#{ddbh}, </if>" +
            "<if test='gh!=null'> pz=#{pz}, </if>" +
            "<if test='time!=null'> devSn=#{devSn}, </if>" +
            "<if test='bc!=null'> xiaolv=#{xiaolv}, </if>" +
            "<if test='org!=null'> dcg=#{dcg}, </if>" +
            "<if test='cj!=null'> zl=#{zl}, </if>" +
            "<if test='kbsj!=null'> ja=#{ja}, </if>" +
            "<if test='ktsj!=null'> yb=#{yb}, </if>" +
            "<if test='ttsj!=null'> gs=#{gs}, </if>" +
            "<if test='yl!=null'> chph=#{chph}, </if>" +
            "<if test='xiaolv!=null'> jhts=#{jhts}, </if>" +
            "</trim> " +
            " WHERE id=#{id}" +
            "</script>")
    int updateScjhSec(MesNewscjhInfo mesNewscjhInfo);

}
